home *** CD-ROM | disk | FTP | other *** search
/ Exame Informatica 139 / Exame Informatica 139.iso / Revista / Flash / Uniform Server / diskw / home / admin / www / phpMyBackupPro / scheduled.php < prev    next >
Encoding:
PHP Script  |  2005-07-14  |  11.5 KB  |  235 lines

  1. <?php
  2. /*
  3.  +--------------------------------------------------------------------------+
  4.  | phpMyBackupPro                                                           |
  5.  +--------------------------------------------------------------------------+
  6.  | Copyright (c) 2004-2005 by Dirk Randhahn                                 |
  7.  | http://www.phpMyBackupPro.net                                            |
  8.  | version information can be found in definitions.php.                     |
  9.  |                                                                          |
  10.  | This program is free software; you can redistribute it and/or            |
  11.  | modify it under the terms of the GNU General Public License              |
  12.  | as published by the Free Software Foundation; either version 2           |
  13.  | of the License, or (at your option) any later version.                   |
  14.  |                                                                          |
  15.  | This program is distributed in the hope that it will be useful,          |
  16.  | but WITHOUT ANY WARRANTY; without even the implied warranty of           |
  17.  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            |
  18.  | GNU General Public License for more details.                             |
  19.  |                                                                          |
  20.  | You should have received a copy of the GNU General Public License        |
  21.  | along with this program; if not, write to the Free Software              |
  22.  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.|
  23.  +--------------------------------------------------------------------------+
  24. */
  25.  
  26. require_once("login.php");
  27.  
  28. // used variables
  29. if (!isset($_POST['db'])) $_POST['db']=FALSE;
  30. if (!isset($_POST['tables'])) $_POST['tables']=FALSE;
  31. if (!isset($_POST['data'])) $_POST['data']=FALSE;
  32. if (!isset($_POST['zip'])) $_POST['zip']=FALSE;
  33. if (!isset($_POST['drop'])) $_POST['drop']=FALSE;
  34. if (!isset($_POST['man_dirs'])) $_POST['man_dirs']=FALSE;
  35. if (!isset($_POST['comments'])) $_POST['comments']=FALSE;
  36.  
  37. PMBP_print_header(ereg_replace(".*/","",$_SERVER['SCRIPT_NAME']));
  38.  
  39. // if first use or no db-connection possible
  40. if (!@mysql_connect($CONF['sql_host'],$CONF['sql_user'],$CONF['sql_passwd'])) echo "<div class=\"red\">".I_SQL_ERROR."</div><br>";
  41.  
  42. // check if a db or directory was posted
  43. if (isset($_POST['dirs'])) {
  44.     if (is_array($_POST['db']) || is_array($_POST['dirs']) || $_POST['man_dirs']) $selection_ok=TRUE;
  45.         else $selection_ok=FALSE;
  46. } elseif($_POST['man_dirs']) {
  47.     $selection_ok=TRUE;
  48. } elseif(isset($_POST['db'])) {
  49.     if (is_array($_POST['db'])) $selection_ok=TRUE;
  50.         else $selection_ok=FALSE;
  51. } elseif(isset($_POST)) {
  52.     $selection_ok=FALSE;
  53. }
  54.  
  55. // generate and print php script
  56. if ($selection_ok) {
  57.  
  58.     // create path to run_scheduled.php
  59.     $path_back="";
  60.     if (strstr($_SERVER['SCRIPT_NAME'],"\\")) $delimiter="\\"; else $delimiter="/";
  61.     $script_path=explode($delimiter,$_SERVER['SCRIPT_NAME']);
  62.     $path_d=count(explode("..",$_POST['path']))-1;
  63.     $path_u=count(explode($delimiter,$_POST['path']))-$path_d-1;
  64.     for ($i=0;$i<$path_u;$i++) $path_back.="../";
  65.     for ($i=count($script_path)-$path_d-1;$i<count($script_path)-1;$i++) $path_back.=$script_path[$i]."/";
  66.  
  67.     // set sql server in multi server mode
  68.     if (count($CONF['sql_passwd_s'])) {
  69.         if ($CONF['sql_host']==$_SESSION['sql_host_org'] && $CONF['sql_user']==$_SESSION['sql_user_org']) {
  70.             $_POST['mysql_host']=-1;
  71.         } else {
  72.             for($i=0;$i<count($CONF['sql_passwd_s']);$i++) {
  73.                 if ($CONF['sql_host']==$CONF['sql_host_s'][$i] && $CONF['sql_user']==$CONF['sql_user_s'][$i]) $_POST['mysql_host']=$i;
  74.             }
  75.         }
  76.     }
  77.     
  78.     // generate the dynamic php script
  79.     $result="<?php\n";
  80.     $result.="// This code was created by phpMyBackupPro.".PMBP_VERSION." \n// ".PMBP_WEBSITE."\n";
  81.  
  82.     // list dbs
  83.     if (is_array($_POST['db'])) {
  84.         $result.="\$_POST['db']=array(";
  85.         foreach($_POST['db'] as $value) $result.="\"".$value."\", ";
  86.         $result.=");\n";
  87.     }
  88.  
  89.     // list directories
  90.     if (isset($_POST['dirs'])) {
  91.         $result.="\$_POST['dirs']=array(";
  92.         foreach($_POST['dirs'] as $value) $result.="\"".$value."\", ";
  93.         $result.=");\n";
  94.     }
  95.  
  96.     // print the backup options
  97.     foreach($_POST as $key=>$value) {
  98.         $value=str_replace("\"","'",$value);
  99.         if ($key!="period" && $key!="path" && $key!="db" && $key!="dirs" && $key!="filename" && $value!='')
  100.             $result.="\$_POST['".$key."']=\"".$value."\";\n";
  101.     }
  102.     
  103.     // print the current working database (but always only once)
  104.     if(isset($_SESSION['wss']) && !isset($_POST['mysql_host'])) $result.="\$_POST['mysql_host']=\"".$_SESSION['wss']."\";\n";    
  105.  
  106.     // add include(backup.php) to do all the work
  107.     $result.="\$period=(3600*24)".$_POST['period'].";\n";
  108.     $result.="\$security_key=\"".($PMBP_SYS_VAR['security_key'])."\";\n";
  109.     $result.="// This is the relative path to the phpMyBackupPro.".PMBP_VERSION." directory\n";
  110.     $result.="@chdir(\"".$path_back."\");\n";
  111.     $result.="@include(\"backup.php\");\n";
  112.     $result.="?>";
  113.  
  114.     // show the generated php script
  115.     printf(PMBP_EXS_INCL,$_POST['path']."???.php");
  116.     echo ":\n<br><textarea name=\"code\" rows=\"16\" cols=\"120\" readOnly>".$result."</textarea>\n<br><br>";
  117.     echo "<form name=\"save\" action=\"scheduled.php\" method=\"post\">\n";    
  118.     
  119.     // list all post variables as hidden fields
  120.     foreach($_POST as $key=>$value) {
  121.         if ($key!="db" && $key!="dirs") echo "<input type=\"hidden\" name=\"".$key."\" value=\"".$value."\">\n";
  122.             elseif(is_array($_POST[$key])) foreach($value as $dbname) echo "<input type=\"hidden\" name=\"".$key."[]\" value=\"".$dbname."\">\n";
  123.     }
  124.  
  125.     // save file including the backup script
  126.     if (isset($_POST['filename'])) {
  127.         if (PMBP_save_to_file($_POST['path'].$_POST['filename'],"",$result,"w")) {
  128.             echo "<span class=\"green_left\">".EX_SAVED." ".PMBP_pop_up($_POST['path'].$_POST['filename'],$_POST['path'].$_POST['filename'],"scheduled")."</span><br>\n";
  129.                 
  130.             // save specific settings for scheduled backups
  131.             if ($PMBP_SYS_VAR['EXS_scheduled_file']!=$_POST['filename']) {            
  132.                 $PMBP_SYS_VAR['EXS_scheduled_file']=$_POST['filename'];        
  133.             }
  134.                         
  135.         } else {
  136.             echo "<span class=\"red_left\">".C_WRITE." ".$_POST['path'].$_POST['filename']."</span><br>\n";
  137.         }
  138.     }
  139.     echo PMBP_EXS_SAVE.":<br>\n";
  140.     echo $_POST['path']."<input type=\"text\" name=\"filename\" value=\"".$PMBP_SYS_VAR['EXS_scheduled_file']."\"> ";
  141.     echo "<input type=\"submit\" value=\"".C_SAVE."\">";
  142.     if ($PMBP_SYS_VAR['EXS_scheduled_file']!="???.php")
  143.         echo " (<a href=\"\">".PMBP_pop_up("get_file.php?view=".$_POST['path'].$PMBP_SYS_VAR['EXS_scheduled_file'],B_VIEW,"view")."</a>)";
  144.     echo "</form>";
  145.     echo "\n<a href=\"scheduled.php\"> <- ".EXS_BACK."</a>\n";
  146.  
  147.     // update specific settings for scheduled backups
  148.     if ($_POST['path']!=$PMBP_SYS_VAR['EXS_scheduled_dir'] OR $_POST['period']!=$PMBP_SYS_VAR['EXS_period']) {            
  149.         $PMBP_SYS_VAR['EXS_scheduled_dir']=$_POST['path'];
  150.         $PMBP_SYS_VAR['EXS_period']=$_POST['period'];
  151.     }
  152.     
  153.     // save PMBP_SYS_VARS
  154.     PMBP_save_export_settings();
  155.                 
  156. // print instructions and export form
  157. } else {
  158.     if (isset($selection_ok) && isset($_POST['period'])) echo "<div class=\"red\">".EX_NO_DB."!</div>";
  159.  
  160.     echo "<form name=\"backup\" action=\"scheduled.php\" method=\"post\">\n<div>\n";
  161.     echo EXS_PERIOD.":<br>\n";
  162.     echo "<select name=\"period\">\n";
  163.     if($PMBP_SYS_VAR['EXS_period']=="*0") $selected=" selected"; else $selected="";
  164.     echo "<option value=\"*0\"".$selected.">".PMBP_EXS_ALWAYS."</option>\n";
  165.     echo "<option>---------------------</option>\n";
  166.     if($PMBP_SYS_VAR['EXS_period']=="/24") $selected=" selected"; else $selected="";
  167.     echo "<option value=\"/24\"".$selected.">1 ".EXS_HOUR."</option>\n";
  168.     if($PMBP_SYS_VAR['EXS_period']=="/4") $selected=" selected"; else $selected="";
  169.     echo "<option value=\"/4\"".$selected.">6 ".EXS_HOURS."</option>\n";
  170.     if($PMBP_SYS_VAR['EXS_period']=="/2") $selected=" selected"; else $selected="";
  171.     echo "<option value=\"/2\"".$selected.">12 ".EXS_HOURS."</option>\n";
  172.     echo "<option>---------------------</option>\n";
  173.     if($PMBP_SYS_VAR['EXS_period']=="*1") $selected=" selected"; else $selected="";
  174.     echo "<option value=\"*1\"".$selected.">1 ".EXS_DAY."</option>\n";
  175.     if($PMBP_SYS_VAR['EXS_period']=="*2") $selected=" selected"; else $selected="";
  176.     echo "<option value=\"*2\"".$selected.">2 ".EXS_DAYS."</option>\n";
  177.     if($PMBP_SYS_VAR['EXS_period']=="*3") $selected=" selected"; else $selected="";
  178.     echo "<option value=\"*3\"".$selected.">3 ".EXS_DAYS."</option>\n";
  179.     if($PMBP_SYS_VAR['EXS_period']=="*5") $selected=" selected"; else $selected="";
  180.     echo "<option value=\"*5\"".$selected.">5 ".EXS_DAYS."</option>\n";
  181.     if($PMBP_SYS_VAR['EXS_period']=="*10") $selected=" selected"; else $selected="";
  182.     echo "<option value=\"*10\"".$selected.">10 ".EXS_DAYS."</option>\n";
  183.     echo "<option>---------------------</option>\n";
  184.     if($PMBP_SYS_VAR['EXS_period']=="*7") $selected=" selected"; else $selected="";
  185.     echo "<option value=\"*7\"".$selected.">1 ".EXS_WEEK."</option>\n";
  186.     if($PMBP_SYS_VAR['EXS_period']=="*14") $selected=" selected"; else $selected="";
  187.     echo "<option value=\"*14\"".$selected.">2 ".EXS_WEEKS."</option>\n";
  188.     if($PMBP_SYS_VAR['EXS_period']=="*21") $selected=" selected"; else $selected="";
  189.     echo "<option value=\"*21\"".$selected.">3 ".EXS_WEEKS."</option>\n";
  190.     echo "<option>---------------------</option>\n";
  191.     if($PMBP_SYS_VAR['EXS_period']=="*30") $selected=" selected"; else $selected="";
  192.     echo "<option value=\"*30\"".$selected.">1 ".EXS_MONTH." (30 ".EXS_DAYS.")</option>\n";
  193.     echo "</select>\n<br><br>";
  194.  
  195.     // get content of these directories (I know, it's partly redundant - but I think it's required)
  196.     if ($PMBP_SYS_VAR['dir_lists']>=1) {
  197.         $search_path1="../";
  198.         $dirs1=PMBP_get_dirs($search_path1);
  199.     }
  200.     if ($PMBP_SYS_VAR['dir_lists']>=2) {
  201.         $search_path2="../../";
  202.         $dirs2=PMBP_get_dirs($search_path2);
  203.     }
  204.  
  205.     echo EXS_PATH.": (<a href=\"scheduled.php?update_dir_list=TRUE\">".PMBP_EXS_UPDATE_DIRS."</a>)<br>\n";
  206.     echo "<select name=\"path\">\n";
  207.     if (isset($dirs1)) {
  208.         foreach($dirs1 as $value) {
  209.             if ($PMBP_SYS_VAR['EXS_scheduled_dir']==$search_path1.$value) {
  210.                 echo "<option value=\"".$search_path1.$value."\" selected>".$search_path1.$value."</option>\n";
  211.             } else {
  212.                 echo "<option value=\"".$search_path1.$value."\">".$search_path1.$value."</option>\n";
  213.             }
  214.         }
  215.     }
  216.     echo "<option value=\"\">----------------------------</option>\n";
  217.     if (isset($dirs2)) {
  218.         foreach($dirs2 as $value) {
  219.             if ($PMBP_SYS_VAR['EXS_scheduled_dir']==$search_path1.$value) {
  220.                 echo "<option value=\"".$search_path2.$value."\" selected>".$search_path2.$value."</option>\n";
  221.             } else {
  222.                 echo "<option value=\"".$search_path2.$value."\">".$search_path2.$value."</option>\n";
  223.             }        
  224.         }
  225.     }
  226.     echo "</select>\n<br><br>";
  227.  
  228.     // include the export form (known from the export page) and submitt the file list
  229.     if (isset($dirs1)) PMBP_print_export_form($dirs1); else PMBP_print_export_form();
  230.     echo "\n<input type=\"submit\" value=\"".EXS_SHOW."\" class=\"button\">\n</div>\n</form>";
  231. }
  232.  
  233. PMBP_print_footer();
  234. ?>
  235.